#ifndef _FTEXT_H_
#define _FTEXT_H_

#include "FTextDisplay.h"
#include "FGlyph.h"

namespace Font
{

	class FaceHandle;
	class GlyphMap;
	class LayoutInterface;
	class TextInstructions;
	class GlyphTransform;

	class Text
	{
	
	public:
	
		Text(Library* a_Library, FaceHandle* a_Face);
		~Text();

		void SetInstructions(TextInstructions* a_Instructions);

		void SetCursor(const tb::Vec2& a_Cursor);
		void SetTransform(const tb::Mat3x3& a_Transform);

		bool Write(const unsigned char* a_Message, unsigned int a_Length);
		bool WriteInstructions();

		const tb::Vec2& GetDimensions();
		const tb::Vec2& GetPositionStart();
		const tb::Vec2& GetPositionEnd();

		void SetFont(FaceHandle* a_Font);
		void SetLayout(LayoutInterface* a_Layout);
		void Layout();

		void Render();
	
	protected:

		TextInstructions* m_Instructions;

		tb::Vec2 m_Cursor;
		tb::Mat3x3 m_Transform;
		GlyphTransform* m_GlyphTransform;
		
		tb::Vec2 m_MessagePosStart;
		tb::Vec2 m_MessagePosEnd;
		tb::Vec2 m_MessageDimensions;

		LayoutInterface* m_Layout;
		std::vector<TextDisplay*> m_Display;

		FaceHandle* m_Font;
		Library* m_Library;
	
	}; // class DisplayList

	class TextAbstract
	{
	
	public:
	
		TextAbstract(FaceHandle* a_Font)
		{
			m_Font = a_Font;
		}
		~TextAbstract()
		{

		}

		int GetKerning(GlyphEntry* a_Left, GlyphEntry* a_Right)
		{
			return m_Font->GetKerning(a_Left->glyph->GetCharacter(), a_Right->glyph->GetCharacter());
		}
	
		bool Write(const wchar_t* a_Message)
		{
			m_Message = a_Message;

			return true;
		}

		void Render()
		{
			for (size_t i = 0; i < m_Display.size(); i++)
			{
				m_Display[i]->Render();
			}
		}

	protected:

		FaceHandle* m_Font;

		tb::StringBase<wchar_t> m_Message;

		std::vector<TextDisplay*> m_Display;
	
	}; // class TextAbstract

}; // namespace Font
	
#endif